<script lang="ts" setup>
import { defineEmits, defineProps } from 'vue'
import { HttpStatusCode } from "axios"
import { ElMessage } from "element-plus"
import { energyNature } from '../../../../enums/PersonalChannel'
import { editNewCarClue } from '../../../../api/newCarClue'

const emits = defineEmits(['increase', 'closeShow'])
const prop = defineProps<{
  clueForm: ListNewCarClue
}>()
const submitData = async () => {
  const res = await editNewCarClue(prop.clueForm.id, prop.clueForm)
  if(res.statusCode === HttpStatusCode.Created || res.statusCode === HttpStatusCode.Ok) {
    emits('increase', 1, '')
    emits('closeShow')
    ElMessage({
      message: '修改成功',
      type: 'success',
    })
  } else {
    ElMessage({
      message: '添加失败',
      type: 'error',
    })
  }
}
</script>

<template>
  <div class="container">
    <el-form
        label-position="top"
        label-width="100px"
        :model="prop.clueForm"
        style="max-width: 460px"
    >
      <el-form-item label="线索名称">
        <el-input v-model="prop.clueForm.clueName" />
      </el-form-item>
      <el-form-item label="品牌">
        <el-input v-model="prop.clueForm.brand" />
      </el-form-item>
      <el-form-item label="指导价(万)">
        <el-input-number v-model="prop.clueForm.cluePrice" :precision="1" :step="0.1">
        </el-input-number>
      </el-form-item>
      <el-form-item label="车辆所在地">
        <el-input v-model="prop.clueForm.location" />
      </el-form-item>
      <el-form-item label="能源种类">
        <el-select v-model="prop.clueForm.energy" placeholder="选择能源种类">
          <el-option
              v-for="item in energyNature"
              :key="item.value"
              :label="item.label"
              :value="item.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="排放标准">
        <el-input v-model="prop.clueForm.emissionStandard" :disabled="prop.clueForm.energy === 2" />
      </el-form-item>
      <el-form-item label="排量/变速箱">
        <el-input v-model="prop.clueForm.gearbox" :disabled="prop.clueForm.energy === 2" />
      </el-form-item>
      <el-form-item label="联系电话">
        <el-input v-model="prop.clueForm.phone" />
      </el-form-item>
      <el-form-item label="车辆描述">
        <el-input :rows="2" type="textarea" v-model="prop.clueForm.description" />
      </el-form-item>
      <el-form-item label="所需积分">
        <el-input-number v-model="prop.clueForm.useCoin">
        </el-input-number>
      </el-form-item>
    </el-form>
    <el-button type="primary" @click="submitData">提交</el-button>
  </div>
</template>

<style lang="less" scoped>

</style>